#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/9/21 10:03
# @Author : 闫峰
# @File    : ceshi1.py
import json
from datetime import datetime

import pymongo

from utils.mysqlUtils.mongodb_utils import MongoDBLink
import os
from testcases.financialReconciliation.AliExpress_kingdee.test_collectCompareAliExpressReport import create_sqlserver_database_conn
from testcases.financialReconciliation.AliExpress_kingdee.test_collectCompareAliExpressReport import close_sqlserver_database_conn
from testcases.financialReconciliation.AliExpress_kingdee.test_collectCompareAliExpressReport import exec_query_sql_more

from common.setting import ensure_path_sep
from utils.logging_tool.log_control import LogHandler
from utils.mysqlUtils.db_pool import Database
from utils.mysqlUtils.sql_server_utils import MSSQL

current_path = os.path.abspath(__file__)
current_dir = os.path.dirname(current_path)
path_list = current_path.split("\\")
dis_path = "\\".join(path_list[-2:-1])
info_path = ensure_path_sep(f"\\logs\\info-{dis_path}.log")
error_path = ensure_path_sep(f"\\logs\\\error-{dis_path}.log")
warning_path = ensure_path_sep(f"\\logs\\warning-{dis_path}.log")
if os.path.exists(info_path):
    os.remove(info_path)
if os.path.exists(error_path):
    os.remove(error_path)
if os.path.exists(warning_path):
    os.remove(warning_path)
INFO = LogHandler(info_path, level='info')
ERROR = LogHandler(error_path, level='error')
WARNING = LogHandler(warning_path, level='warning')


class TestChange:
    mapping = {
        "packageLength": "Length",
        "packageWidth": "Width",
        "packageHeight": "Height"
    }

    def test_allocation_bill(self,source_id):

        # erp_db = MSSQL(ensure_path_sep("\\config\\config.yaml"), "sqlserver_db_erp_base")
        erp_db = create_sqlserver_database_conn('erpdb-readonly.zhcxkj.com', 1433, 'irobotboxuser',
                                                  'HskwPanda047RAHRAxqktlref', 'irobotbox')
        # 遍历RB_Inventory_DetailLog库，验证allocation_bill
        get_BillNumber = """
         SELECT a.AliExpressCategoryID,a.AliExpressAttributeID,a.AliExpressAttributeValueID
         FROM [irobotbox].[dbo].[RB_AliExpress_AttributeValues] (nolock) a
         LEFT JOIN [irobotbox].[dbo].[RB_AliExpress_Attribute] (nolock) b ON a.AliExpressCategoryID=b.AliExpressCategoryID AND a.AliExpressAttributeID=b.AliExpressAttributeID
         WHERE b.OrderSourceID= 18337
         AND b.CNName = '品牌'
         AND b.CustomerID=1
         GROUP BY a.AliExpressCategoryID,a.AliExpressAttributeID,a.AliExpressAttributeValueID
        """
        # res = erp_db.ExecQuery_dict(get_BillNumber,())
        res = exec_query_sql_more(get_BillNumber,erp_db)

        for data in res:
            get_AttributeValueName = """
             SELECT 
         AttributeValueName
            FROM RB_AliExpress_AttributeValues (nolock)
            WHERE  AliExpressCategoryID=%s
           and AliExpressAttributeID=%s
                 AND AliExpressAttributeValueID=%s
            """
            # AttributeValueName = erp_db.ExecQuery(get_AttributeValueName, (data[]))






if __name__ == '__main__':
    TestChange().test_allocation_bill(18337)
